<template>
  <el-dialog  :destroy-on-close="true" :lock-scroll="false" title="工单审核" :visible.sync="visible"  :before-close="() => {$emit('cancel');}"
              custom-class="ele-dialog-form" width="600px">
    <el-form :model="returnData"  :rules="rules" ref="returnForm">
      <el-form-item label="审核备注：" prop="content">
        <el-input v-model="returnData.content" :rows="3" placeholder="请输入审核备注" type="textarea" />
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="cancel" type="primary">取消</el-button>
      <el-button :loading="loading" type="primary" @click="save">完成审核</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: "audit",
  props: {
    // 弹窗是否打开
    visible: Boolean,
    id: {
      type:[String,Number]
    }
  },

  data() {
    return {
      rules: {
        content: [
          { required: true, message: "请输入审核内容", trigger: "blur" }
        ]
      },
        loading:false,
        returnData:{},
    };
  },

  mounted() {

  },

  methods: {
    //提交审核
    save() {
      this.$refs['returnForm'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$http.post(`/wos/${this.id}/audit`,{...this.returnData}).then(res => {
            if (res.data.code === 0) {
              this.$message.success(res.data.msg);
              this.$emit('done')
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            this.$message.error(e.message);
          });
        } else {
          this.loading = false;
          return false;
        }
        this.loading = false;
        this.returnData={}
      });
    },
    //取消审核
    cancel(){
      this.$emit('cancel')
    }
  }
};
</script>
